let box1 = document.querySelector('.content')
let box2 = document.querySelector('.actor-1');
let box3 = document.querySelector('.video-1');
let box4 = document.querySelector('.comment-1')

// 获取地址栏id
let reg = /id=(\d+)/;
let id = reg.exec(location.search)[1];

// 请求数据 https://wx.maoyan.com/mmdb/movie/v5/电影的id.json?ci=20
pAjax({
    url:`/my/movie/v5/${id}.json`,
    data:{
        ci:20
    }
}).then(function(res){
    res = JSON.parse(res)
    res = res.data.movie;
    details(res);
})
function details(res){
    box1.innerHTML = ` 
        <div class="details">
            <div class="top">
                <img src="${res.img.replace('/w.h','')}@464w_644h_1e_1c""/>
                <div>
                    <p>${res.scm}</p>
                    <p>${res.snum}人想看</p>
                    <p>${res.cat}</p>
                    <p>中国大陆</p>
                    <p>${res.pubDesc}</p>
                </div>
            </div>
            <div class="buttom">
                <a><i class="iconfont iconxihuan"></i><span>想看</span></a>
                <a><i class="iconfont iconpingfen"></i><span>评分</span></a>
            </div>
        </div>
        <div class="brief">
            <span>${res.dra}</span>
        </div>`    
}


// 请求数据 
// 电影详情/演职人员:https://wx.maoyan.com/mmdb/v7/movie/1351039/celebrities.json
pAjax({
    url:`/my/v7/movie/${id}/celebrities.json`,
}).then(function(res){
    res = JSON.parse(res)
    res = res.data[1]
    // console.log(res);
    actor(res);
})
function actor(res1){
    let str = '';
        res1.forEach((item,index) => {
            // console.log(item);
            str += `<figure>
            <img src="${item.avatar.replace('/w.h','')}"/>
            <figcaption>
                <p>${item.cnm}</p>
                <p>${item.desc}</p>
            </figcaption>
        </figure>`   
    });
    box2.innerHTML = str;
}

// 请求数据
//电影详情/视频和剧照： https://wx.maoyan.com/mmdb/movie/photos/1351039/list.json
pAjax({
    url:`/my/movie/photos/${id}/list.json`,
}).then(function(res){
    res = JSON.parse(res)
    res = res.data.photos;
    // console.log(res);
    video(res);
})
function video(res){
    let str = '';
        res.forEach((item,index) => {
            str += `<figure>
            <img src="${item.tlink.replace('/w.h','')}"/>
        </figure>`   
    });
    box3.innerHTML = str;
}

// 电影详情/评论信息:
// https://wx.maoyan.com/mmdb/comments/movie/v2/1351039.json?limit=3&offset=0&uuid=1A6E888B4A4B29B16FBA1299108DBE9C25451D87F2A6D22D0F67C5092D7994D0&token=&ci=20&clientType=wechat_small_program&channelId=40000

pAjax({
    url:`/my/comments/movie/v2/${id}.json`,
    data:{
        limit:3,
        offset:0,
        uuid:"1A6E888B4A4B29B16FBA1299108DBE9C25451D87F2A6D22D0F67C5092D7994D0",
        ci:20,
        clientType:"wechat_small_program",
        channelId:40000
    }
}).then(function(res){
    res = JSON.parse(res)
    res = res.hcmts;
    // console.log(res);
    comment(res);
})
function comment(res){
    let str = '';
        res.forEach((item,index) => {
            str += ` <figure>
            <img src="${item.avatarurl}"/>
            <figcaption>
                <a>${item.nickName}</a>
                <a><i class="iconfont iconpingfen"></i>
                <i class="iconfont iconpingfen"></i>
                <i class="iconfont iconpingfen"></i>
                <i class="iconfont iconpingfen"></i></a>
            </figcaption>
        </figure>
        <span>${item.content}</span>`   
    });
    box4.innerHTML = str;
}